function setLocation(href){
    location.href = href;
}

String.prototype.trim = function(){
    return $.trim(this);
};

String.prototype.format = function(args){
    var str = this;
    var arr = str.match(/\{(\w+)\}/gi);
    for(var i = 0; i < arr.length; i++){
        var l = arr[i].length;
        str = str.replace(arr[i], args[arr[i].substring(1, l - 1)]);
    }
    return str;
};

String.prototype.pad = function(len, flag, type){
    var str = this;
    if(str.length < len){
        while(str.length < len){
            switch(type){
                case 'l':
                    str = flag + str;
                    break;
                case 'r':
                    str = str + flag;
                    break;
                default:
                    str = str + flag;
                    break;
            }
        }
    }
    return str;
};

jQuery.validator.addMethod('character', function(value){
    return /^\w+$/.test(value);
});

jQuery.validator.addMethod('rangeLength', function(value, element, params){
    return value.length >= params[0] && value.length <= params[1];
});

var Kdf = {
    extend: function(bc, sc, o) {
        var f = function() {};
        f.prototype = sc.prototype;
        bc.prototype = new f();
        bc.prototype.constructor = bc;
        bc.superclass = sc.prototype;
        for (var m in o){
            bc.prototype[m] = o[m];
        }
    },

    setScope: function(callback, scope) {
        return function() {
            return callback.apply(scope, arguments);
        };
    },

    namespace: function() {
        var ns, d;
        for (var i = 0; i < arguments.length; i++) {
            ns = window;
            d = arguments[i].split(".");
            for (var j in d){
                ns = ns[d[j]] = ns[d[j]] ? ns[d[j]] : {};
            }
        }
    },

    isObject: function(obj) {
        return (obj && obj.constructor && obj.constructor == Object.prototype.constructor && !obj.nodeName)
        ? true : false;
    },

    globals:{
        forms:[],
        grids:[]
    },

    copyright: 'Keep Doing Studio'
};

Kdf.Base = function() {
    if (Kdf.isObject(arguments[0])) {
        var config = arguments[0];
        Kdf.Base.superclass.init.call(this);
        this.initialize(config);
    } else {
        arguments.length > 0?
        Kdf.Base.superclass.init.apply(this, arguments):
        Kdf.Base.superclass.init.call(this);
    }
};

Kdf.extend(Kdf.Base, jQuery, {
    initialize: function(config) { }
});

Kdf.Ajax = {};
Kdf.Ajax.processResult = function(data, textStatus, request, setting){
    setting.resultHandler(data);
    return true;
};

Kdf.Ajax.processError = function(request, textStauts){
    alert(request.statusText);
};

Kdf.Ajax.load = function(setting){
    var config = jQuery.extend({}, {
        data:{},
        dataType:'text',
        method:'GET',
        cache: false
    }, setting);
    if(!config.resultHandler){
        config.resultHandler = function(data){
            config.success(data);
        };
    }

    jQuery.ajax({
        url:config.url,
        data:config.data,
        dataType:config.dataType,
        method:config.method,
        success:function(data, textStatus, request){
            Kdf.Ajax.processResult(data, textStatus, request, setting);
        },
        error:function(request, textStatus, errorThrown){
            Kdf.Ajax.processError(request, textStauts, errorThrown);
        }
    });
};

Kdf.Ajax.loadJson = function(setting){
    setting.dataType = 'text';
    setting.resultHandler = function(data){
        var json = eval('(' + data + ')');
        setting.success(json);
    };
    Kdf.Ajax.load(setting);
};

Kdf.Ajax.loadHtml = function(setting){
    setting.dataType = 'html';
    setting.resultHandler = function(data){
        setting.success(data);
    };
    Kdf.Ajax.load(setting);
};